package server;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.transfermodel.BeatPackage;
import model.transfermodel.OrderPackage;
import tools.SysAlert;
import DBtools.HeartBeatBO;
import DBtools.OrderBO;

import com.alibaba.fastjson.JSON;

public class SetOrderServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter out=resp.getWriter();
		out.println("<html><body><h1>This is a servlet test SetOrderServlet . welcome</h1></body></html>");
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("text/html;charset=utf-8");
		
		PrintWriter out=resp.getWriter();
		String jsonString=(String) req.getParameter("object");
		SysAlert.info("SetOrderServlet", jsonString);
		OrderPackage pack = null;

		
		
		if(jsonString != null){
			pack = JSON.parseObject(jsonString, OrderPackage.class);
		}
		
		
		if(pack != null){
			OrderBO orderBO = new OrderBO();
			orderBO.addOrder(pack);
		}else{
			SysAlert.error("SetOrderServlet", "package is null");
		}
		out.println("welcome!");
		out.flush();
	}

}
